import { login } from '@/api'
import { getToken, setToken, removeToken } from '@/utils/auth'
export default {
  namespaced: true,
  state: {
    token: getToken() || ''
  },
  mutations: {
    // 存储token
    SET_TOKEN(state, token) {
      state.token = token
      setToken(token)
    },
    removeUserInfo(store) {
      // 清除vuex中的token
      store.token = ''
      // 和本地的token
      removeToken()
    }
  },
  actions: {
    // 登录
    // 此处token报错，返回字段 res 写错 与人资的{data}相同  token存储undefined
    async Signin(store, loginForm) {
      const res = await login(loginForm)
      store.commit('SET_TOKEN', res.token)
      return res
    }
  }
}
